package com.ceshiren.chnjx.wework.page;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

/**
 * @author JJJJ
 * @Title: app
 * @date 2021/11/6下午4:17
 * @Description: 作为app测试的入口 初始化driver
 */
public class App extends BasePage {

    public App() {
        initDriver();
    }

    public void initDriver() {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        // 使用的操作系统
        capabilities.setCapability("platformName","Android");
        // 设备名称
        capabilities.setCapability("deviceName","mate40");
        // app包名
        capabilities.setCapability("appPackage","com.tencent.wework");
        // app应用名
        capabilities.setCapability("appActivity",".launch.LaunchSplashActivity");
        // 是否重置app信息 比如权限授予
        capabilities.setCapability("noReset",true);
        // 执行结束后不关闭app
//        capabilities.setCapability("dontStopAppOnReset","true");
        // 使用的automation版本 新版本appium默认使用 UiAutomator2
        capabilities.setCapability("automationName","UiAutomator2");

        try {
            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
            driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

    }

    public MainPage Start(){
        return new MainPage(driver);
    }
}
